package com.itheima.edu.info.manager.controller;

import com.itheima.edu.info.manager.domain.Student;
import com.itheima.edu.info.manager.util.DateUtil;

import java.util.Scanner;

/*
客服类:
专门和用户打交道的
*/
public class OtherStudentController extends BaseStudentController {
    private String name;
    private String age;
    private String birthday;

    //封装学生对象
    public Student getStudent(String id) {
        /*Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名:");
        String name = sc.next();
        System.out.println("请输入生日:[格式为:yyyy-mm-dd],[年龄在15-60之间]");
        String birthday= sc.next();
        String age = DateUtil.getAgeByBirthday(birthday)+"";
        Student student = new Student(id, name, age, birthday);
        return student;
        */
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名:");
        name = sc.next();
        while(true) {
            System.out.println("请输入生日:[格式为:yyyy-mm-dd],[年龄在15-100之间]");
            birthday = sc.next();
            int ageTemp = DateUtil.getAgeByBirthday(birthday);
            if (15<ageTemp&&ageTemp<100){
                age=ageTemp+"";
                break;
            }else if (ageTemp<15&&ageTemp>0){
                System.out.println("年龄太小,不符合黑马学生标准");
                System.out.println("添加不成功!");
                try {
                    start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else if(ageTemp>=100){
                System.out.println("年龄太大,不符合黑马学生标准");
                System.out.println("添加不成功!");
                try {
                    start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                System.out.println("生日格式不对||年龄太小");
                System.out.println("添加不成功!");
                try {
                    start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        Student student = new Student(id, name, age, birthday);

        return student;
    }

}
